//
// Created by vista on 2017/12/17.
//

#ifndef P_P20_H
#define P_P20_H

#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <set>
using namespace std;

class Solution {
public:
    bool isValid(string s) {
        int l = 0,r = s.length() -1;
        if((r & 1) == 0 || r < 0)
            return false;
        stack<char> stack1;
        while (l <= r)
        {
            if(s[l] == '(' || s[l] == '[' || s[l] == '{')
                stack1.push(s[l]);
            else{
                if(stack1.empty())
                    return false;
                char t = stack1.top();
                if( (s[l] == ')' && t == '(') || (s[l] == ']' && t == '[') || (s[l] == '}' && t == '{')){
                    stack1.pop();
                }else
                    return false;
            }
            ++l;
        }
        return stack1.empty();
    }
};

#endif //P_P20_H
